#pragma once

#include <memory>

#include "Containers/String.h"
#include "Path/Path.h"
#include "ScriptCompiler/Token/FilePosition.h"

#include <stack>

class CASTNode;
class CScriptToken;
class IASTBuilder;
class CNamespaceNode;
class CCompilerContext;
class CScriptFileContext
{
public:    
    CScriptFileContext(std::weak_ptr<CCompilerContext> InCompiler,  const CString& CSFileContent ,const SPath& FilePath );

    SPath FilePath;
    std::weak_ptr<CCompilerContext> Compiler;
    TVector<char32_t> FileContent;
    void RaiseError(uint64_t ErrorCode,uint64_t LineIndex,uint64_t ColumnIndex,uint64_t CharNum,const CString & InErrorMessage,bool bIsWarning=false);
    void RaiseError(uint64_t ErrorCode,const SScriptFilePosition& PositionInFile , const CString & InErrorMessage,bool bIsWarning=false);
    void RaiseError(uint64_t ErrorCode,std::shared_ptr<CScriptToken> InToken,const CString & InErrorMessage,bool bIsWarning=false);
    void RaiseError(uint64_t ErrorCode,const CString & InErrorMessage,bool bIsWarning=false);

    //1. generate tokens
    TVector<std::shared_ptr<CScriptToken>> TokenList;
    TVector<uint64_t> LineStartIndexList; //start from 0
    void DebugPrintTokenList();
    uint32_t GetLineCount();

    //2. generate AST
    std::shared_ptr<CNamespaceNode> ASTRoot;
    uint64_t CurrentTokenIndex=0;
    std::shared_ptr<CScriptToken> GetFormerToken();
    std::shared_ptr<CScriptToken> GetCurrentToken();
    std::shared_ptr<CScriptToken> GetNextToken();   
    std::shared_ptr<CScriptToken> GetNextNextToken();
    std::shared_ptr<CScriptToken> GetToken(uint64_t Index);


    //4 code generation stage things
    uint32_t FileIndex=0;
};
